package com.tencent.cloud.uikit.widget.button;


import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;

import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButtonDrawable;
import com.tencent.cloud.iov.util.R;

/**
 * @author vinsonhuang
 * @date 2018/6/29
 */
public class RoundButton extends QMUIRoundButton {

    public RoundButton(Context context) {
        super(context);
        init(context, null);
    }

    public RoundButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public RoundButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        QMUIRoundButtonDrawable buttonDrawable = (QMUIRoundButtonDrawable) getBackground();
        buttonDrawable.setStroke(1, Color.WHITE);

        int bgColor = Color.WHITE;
        int textColor = Color.BLACK;
        if (null != attrs) {
            TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.RoundButton);
            bgColor = ta.getColor(R.styleable.RoundButton_bgColor, Color.WHITE);
            textColor = ta.getColor(R.styleable.RoundButton_wordColor, Color.BLACK);
        }
        buttonDrawable.setColor(bgColor);
        setTextColor(textColor);
    }

}
